package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// TerminalConfigLog 终端配置记录
type TerminalConfigLog struct {
	ID           string `json:"id" gorm:"primaryKey;column:id;type:int;size:64;comment:主键"`
	RobotID      string `json:"robot_id" gorm:"column:robot_id;type:string;size:40"`
	TerminalType string `json:"terminal_type" gorm:"column:terminal_type;type:string;size:40"`
	Key          string `json:"key" gorm:"column:key;type:string;size:40;comment:配置的key"`
	OldValue     string `json:"old_value" gorm:"column:old_value;type:string;size:100;comment:配置的值-旧"`
	NewValue     string `json:"new_value_new" gorm:"column:new_value;type:string;size:100;comment:配置的值-新"`
	UserID       string `json:"user_id" gorm:"column:user_id;type:int;default:0;size:64;comment:用户id"`
	CreatedAt    int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt    int64  `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名称
func (TerminalConfigLog) TableName() string {
	return "terminal_config_log"
}

// BeforeCreate 自增id
func (t *TerminalConfigLog) BeforeCreate(tx *gorm.DB) (err error) {
	if t.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	t.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &TerminalConfigLog{})
}
